package com.tc.service.impl;

import com.tc.R;
import com.tc.entity.Order;
import com.tc.feign.FGoodsService;
import com.tc.mapper.MyOrderMapper;
import com.tc.mapper.OrderGoodsMapper;
import com.tc.service.MyOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Author: wangyifan
 * @Date: 2022/03/03 11:54
 * @Description: $end$
 * @Version: V1.0
 */

@Service

public class MyOrderServiceImpl implements MyOrderService{

    @Autowired(required = false)
    private MyOrderMapper myOrderMapper;
    @Autowired
    private FGoodsService goodsService;
    @Autowired(required = false)
    private OrderGoodsMapper orderGoodsMapper;


    @Override
    public R addOrder(Order order) {
        R r = new R();
        Integer result = myOrderMapper.addOrder(order);
//        订单商品表的操作
        Integer result2 = orderGoodsMapper.add(order.getOrderCommodity());
        if(result > 0){
            r.setCode(200);
            r.setMsg("增加订单成功");
            System.out.printf("创建订单并支付成功");
            System.out.printf("==调用减商品库存方法==");
            R rr = goodsService.reduceGoods(order.getOrderCommodity().getCommodity_order_id(),order.getOrderCommodity().getCommodity_number());

        }else {
            r.setCode(500);
            r.setMsg("增加订单失败");
            System.out.printf("创建订单失败");
        }

        return r;
    }
}
